package com.hzc.springchan.config.oss;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * OSS相关bean初始化
 * @author chen990627
 * @date 2022/10/19
 */
@Component
@ConditionalOnBean(OSSConfig.class)
public class BeanConfig {

    @Bean
    public OSS oss(OSSConfig ossConfig) {
        return new OSSClientBuilder()
                .build(
                        ossConfig.getEndpoint(),
                        ossConfig.getAccessKeyId(),
                        ossConfig.getAccessKeySecret()
                );
    }
}
